﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PokerClient.VisualDisp;
using System.Windows.Forms;
using PokerClient.Connection.Interfaces;

namespace PokerClient.Connection.CommandHandlers
{
	class authProtHandles : absAuthReg , IHandle
	{
		private MainWindow login;
		private AuthRegStates state;
		public String message = "";
		private Client myClient;

		public authProtHandles(MainWindow login, Client myClient)
		{
			this.login = login;
			this.myClient = myClient;
			
		}

		public override void assignCommand(String commands)
		{
			this.commands = commands.Split(' ');
		}
		public override void analyze()
		{
			switch(state)
			{
				case AuthRegStates.AUTH_FAIL:
					login.updateStatus(message);
					//((MainWindow)login).enableButtons();
					break;
				case AuthRegStates.AUTH_SUCCES:
					myClient.usern = commands[1];
					myClient.chip = commands[2];
					(login).updateStatus(message);	
					//((MainWindow)login).disableButtons();
					break;
			}
		}
		public override string work()
		{
			String ans = "";
			switch(commands[0])
			{
				case "AUTH-FAIL":
					ans = commands[1];
					state = AuthRegStates.AUTH_FAIL;
					break;
				case "AUTH-ACK":
					ans = "AuthSuccess";					
					state = AuthRegStates.AUTH_SUCCES;
					break;
				default:
					ans = "Fail!";
					state = AuthRegStates.AUTH_FAIL;
					break;
			}
			return (message = ans);
		}
	}
}
